import React, {useState} from "react";
import {useHistory} from "react-router-dom";
import UserMsg from "../../outUser/userMsg/UserMsg";
import {InputItem, List, Modal, Toast} from "antd-mobile";
import Btn from "../../../components/btn/Btn";
import http from "../../../model/http";
import {sendMsg} from "../../../model/code";


function Card() {
  const history = useHistory();

  const [money,setMoney] = useState(0);

  const submit = ()=>{
    if(money<=0){Toast.fail('请输入充卡金额');return};

    Modal.alert('提示', '确认开单', [
      { text: '取消'},
      { text: '开单', onPress: async ()=>{
          const order = await http.post('/bill/subcard',{customerCrmId:history.location.state.customerCrmId, cardmoney:money});
          sendMsg(order.jumpUrl,'储蓄充卡',`${order.mangerName} 已为您创建订单，请支付`);
          console.log(order);
        }},
    ])
  };

  return (
      <div>
        <UserMsg msg={history.location.state} />

        <List className='g-mb10 g-bdrs12 g-ov g-bg-f'>
          <InputItem type='number' value={money||''} onChange={v=>{setMoney(v-0)}} extra='元' moneyKeyboardAlign='right'>充卡金额</InputItem>
        </List>

        <Btn type='primary' onClick={submit}>确认并发送给顾客</Btn>
      </div>
  )
}

export default Card;